Skip to content

SOLR-18157: Optimize buffer allocation in JavaBinCodec#4208

Merged
psalagnac merged 2 commits intoapache:mainfrom
psalagnac:javabin-buffer
Mar 19, 2026
Merged

SOLR-18157: Optimize buffer allocation in JavaBinCodec#4208
psalagnac merged 2 commits intoapache:mainfrom
psalagnac:javabin-buffer

Conversation

@psalagnac
Copy link
Copy Markdown
Contributor

https://issues.apache.org/jira/browse/SOLR-18157

This implements a smarter allocation strategy using powers of 2 for the internal buffer of JavaBinCodec. The goal is to reduce the number of allocations.

Added a JMH benchmark suite to measure serialization performance with different batch sizes. I see a small improvement in throughput locally. I expect the impact to be slightly higher in JVMs with big heap for other reasons.

### Before
Benchmark             (batchSize)   (type)   Mode  Cnt     Score     Error  Units
RequestWriters.write           10  javabin  thrpt    5  5770,665 ± 636,538  ops/s
RequestWriters.write          100  javabin  thrpt    5   591,845 ±  11,787  ops/s
RequestWriters.write         1000  javabin  thrpt    5    58,766 ±   8,620  ops/s
RequestWriters.write        10000  javabin  thrpt    5     5,980 ±   0,044  ops/s

### AFTER
Benchmark             (batchSize)   (type)   Mode  Cnt     Score     Error  Units
RequestWriters.write           10  javabin  thrpt    5  5824,500 ± 482,134  ops/s
RequestWriters.write          100  javabin  thrpt    5   601,498 ±   4,600  ops/s
RequestWriters.write         1000  javabin  thrpt    5    59,621 ±   0,995  ops/s
RequestWriters.write        10000  javabin  thrpt    5     5,988 ±   0,108  ops/s

Implements a smarter allocation strategy using powers of 2 for the internal buffer of JavaBinCodec.
Copy link
Copy Markdown
Contributor

@dsmiley dsmiley left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nicely done Pierre!

I was about to suggest Lucene ArrayUtil.oversize for this but then realized that's not possible for SolrJ.

@psalagnac psalagnac merged commit f3fe28b into apache:main Mar 19, 2026
5 of 6 checks passed
@psalagnac psalagnac deleted the javabin-buffer branch March 19, 2026 10:12
psalagnac added a commit that referenced this pull request Mar 19, 2026
 Implements a smarter allocation strategy using powers of 2 for the internal buffer of JavaBinCodec.

(cherry picked from commit f3fe28b)
psalagnac added a commit that referenced this pull request Mar 19, 2026
 Implements a smarter allocation strategy using powers of 2 for the internal buffer of JavaBinCodec.

(cherry picked from commit f3fe28b)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants